package com.groupware.gw.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.groupware.gw.dao.GWDao;
import com.groupware.gw.model.GWModel;
import com.groupware.member.model.MemberModel;

public class GWService implements GWDao{
	private SqlMapClientTemplate sqlMapClientTemplate;
	private HashMap<String, Object> valueMap = new HashMap<String, Object>();
		

	public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
		this.sqlMapClientTemplate = sqlMapClientTemplate;
	}

	@Override
	public int getGWTotalNum(String userId) {
		return (Integer) sqlMapClientTemplate.queryForObject("gw.getGWTotalNum", userId);
	}
	
	@Override
	public List<GWModel> getGWList(String userId) {
		valueMap.put("userId", userId);
		return sqlMapClientTemplate.queryForList("gw.getGWList", valueMap);
	}
	
	@Override
	public List<GWModel> getGWApproveList(String userId) {
		valueMap.put("userId", userId);
		return sqlMapClientTemplate.queryForList("gw.getGWApproveList", valueMap);
	}
	
	@Override
	public GWModel getOneGWArticle(int document_no){
		return (GWModel) sqlMapClientTemplate.queryForObject("gw.getOneGWArticle", document_no);
	}

	@Override
	public List<MemberModel> getUserName(String userId) {
		valueMap.put("userId", userId);
		return sqlMapClientTemplate.queryForList("gw.getUserName", valueMap);
	}
	
	@Override
	public MemberModel getOneUserName(String userId) {
		valueMap.put("userId", userId);
		return (MemberModel)sqlMapClientTemplate.queryForObject("gw.getOneUserName", userId);
	}
	
	@Override
	public boolean writeGWArticle(GWModel gwModel) {
		sqlMapClientTemplate.insert("gw.writeGWArticle", gwModel);		
		return true;
	}

	@Override
	public int updateApprove(int document_no, String approveDate, int step) {
		System.out.println("데이트"+approveDate);
		valueMap.put("document_no", document_no);
		valueMap.put("approveDate", approveDate);
		valueMap.put("step", step);
		return sqlMapClientTemplate.update("gw.updateApprove", valueMap);
	}

	@Override
	public int deleteArticle(int document_no) {
		valueMap.put("document_no", document_no);
		return sqlMapClientTemplate.delete("gw.deleteApprove", valueMap);
	}

	@Override
	public boolean modifyGWArticle(GWModel gwModel) {
		sqlMapClientTemplate.update("gw.modifyGWArticle", gwModel);
		return true;
	}
	
}
